home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / CRYPT19.ZIP / EN_EXE.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-08-05  |  6.7 KB  |  249 lines

  1. ;─────────────────────────────────────────────────────────────────────────────
  2. ;                   Black Wolf's File Protection Utilities 2.1s
  3. ;
  4. ;
  5. ;EN_EXE - Decryption Code for EXE file encryption protection in EncrEXE.
  6. ;         If modified, convert to data bytes and re-instate program into
  7. ;         EncrEXE.ASM, then recompile EncrEXE.
  8. ;      
  9. ;         Basically, this code is attached to a .EXE file and, when executed,
  10. ;         decrypts the .EXE file and continues execution.
  11. ;
  12. ;LISCENSE:
  13. ;    Released As Freeware - These files may be distributed freely.
  14. ;
  15. ;Any modifications made to this program should be listed below the solid line,
  16. ;along with the name of the programmer and the date the file was changed.
  17. ;Also - they should be commented where changed.
  18. ;
  19. ;NOTE THAT MODIFICATION PRIVILEDGES APPLY ONLY TO THIS VERSION (2.1s)!  
  20. ;I'd appreciate notification of any modifications if at all possible, 
  21. ;reach me through the address listed in the documentation file (bwfpu21s.doc).
  22. ;
  23. ;DISCLAIMER:  The author takes ABSOLUTELY NO RESPONSIBILITY for any damages
  24. ;resulting from the use/misuse of this program/file.  The user agrees to hold
  25. ;the author harmless for any consequences that may occur directly or 
  26. ;indirectly from the use of this program by utilizing this program/file
  27. ;in any manner.
  28. ;─────────────────────────────────────────────────────────────────────────────
  29. ;Modifications:
  30. ;       None as of 08/05/93 - Initial Release.
  31.  
  32. .model tiny
  33. .radix 16
  34. .code
  35.         org 100
  36. start:
  37. ;        push    es ds
  38. ;                       ;These commands are placed _before_ the ultimute
  39. ;        push    cs cs  ;encryption.
  40. ;        pop     es ds
  41.         call    Get_Offset
  42.  
  43. Displaced:
  44.         pop     ax        
  45.         push    ax
  46.  
  47. Hackit:
  48.         mov     word ptr cs:[ES_Store+bp],ax    ;save ES
  49.         mov     word ptr cs:[tricky+bp],ax      ;Trash next command if
  50. Tricky:                                         ;debugged
  51.         xor     bx,bx
  52.         add     ax,10
  53.         mov     cx,cs
  54.         sub     cx,ax
  55.         shl     cx,1
  56.         adc     bx,0
  57.         jmp     nextset
  58.         db      0ea             ;confuse disassemblers
  59. lastset:
  60.         shl     bx,1
  61.         shl     cx,1
  62.         adc     bx,0
  63.         jmp     short doneset        
  64.         
  65.         db      0ff             ;same as above
  66. nextset:        
  67.         shl     bx,1
  68.         shl     cx,1
  69.         adc     bx,0
  70.         jmp     short lastset
  71.         db      9a
  72.  
  73. doneset:
  74.         mov     es,ax
  75.         mov     ds,ax
  76.         xor     si,si
  77.         xor     di,di
  78.         call    Waiter
  79.         
  80.         jmp     short Decrypt_Loop
  81.         db      0ea
  82. Decrypt_Loop:                           ;Decrypt EXE - needs work on alg.
  83.         lodsw
  84.         xor     ax,[Key1+bp]
  85.         add     ax,[Key2+bp]
  86.         ror     ax,1
  87.         xor     ax,[Key3+bp]
  88.         sub     ax,[Key4+bp]
  89.         rol     ax,1
  90.         
  91.         stosw
  92.         
  93.         push    bx cx
  94.         mov     ax,si
  95.         mov     bx,ax        
  96.         mov     cl,4
  97.         shr     ax,cl
  98.         shl     ax,cl
  99.         cmp     ax,bx
  100.         jne     DoneReset
  101.         sub     si,10
  102.         sub     di,10
  103.         push    ds
  104.         pop     ax
  105.         inc     ax
  106.         mov     ds,ax
  107.         mov     es,ax
  108. DoneReset:        
  109.         pop     cx bx
  110.         loop    Decrypt_Loop
  111.         
  112.         cmp     bx,0
  113.         je      Int_00
  114.         dec     bx
  115.         jmp     Decrypt_Loop
  116.         call    Waiter
  117.  
  118. Int_00:                 ;Div by Zero Anti-Debug trick....
  119.         push    ax ds
  120.         xor     ax,ax
  121.         mov     ds,ax
  122.         lea     ax,[Restorat+bp]
  123.         xchg    ax,ds:[0]
  124.         push    ax
  125.         mov     ax,cs
  126.         xchg    ax,ds:[2]
  127.         push    ax
  128.         
  129.         xor     cx,cx
  130.         mov     word ptr cs:[divideit+bp],9090
  131. divideit:
  132.         div     cx
  133.        
  134.         pop     ax
  135.         xchg    ax,ds:[2]
  136.         pop     ax
  137.         xchg    ax,ds:[0]
  138.         pop     ds ax
  139.  
  140. Restore_EXE:        
  141.         pop     es ds        
  142.         
  143.         mov     ax,word ptr cs:[ES_Store+bp]
  144.         add     ax,10
  145.         add     ax,word ptr cs:[Old_SS+bp]
  146.         
  147.         cli
  148.         mov     ss,ax
  149.         mov     sp,word ptr cs:[Old_SP+bp]
  150.         sti
  151.  
  152.         xor     ax,ax
  153.         mov     si,ax
  154.         mov     di,ax
  155.         jmp     dword ptr cs:[Old_IP+bp]        ;jump back to host file
  156.  
  157.  
  158. Restorat:
  159.         mov     ax,word ptr cs:[ES_Store+bp]
  160.         add     ax,10
  161.         add     word ptr cs:[Old_CS+bp],ax
  162.         call    Undo_Relocation
  163.         iret
  164. ;------------------------------------------------------------------------
  165. Undo_Relocation:                      ;Add old ES+10 to all addresses in
  166.                                       ;Relocation table for program to run.
  167.         push    ax bx cx dx es ds si di bp
  168.         mov     bx,bp
  169.  
  170.         mov     bp,word ptr cs:[Header+18+bx] ;Get offset of first relocation item
  171.         mov     cx,word ptr cs:[Header+6+bx]
  172.         or      cx,cx
  173.         jz      Done_UnReloc
  174. UnReloc_Loop:
  175.         add     bp,bx
  176.         lds     si,dword ptr cs:[Header+bp]
  177.         sub     bp,bx
  178. UnDo_Reloc:
  179.         mov     ax,ds
  180.         add     ax,word ptr cs:[ES_Store+bx]       ;adjust DS
  181.         add     ax,10
  182.         mov     ds,ax
  183.  
  184.         mov     ax,word ptr cs:[ES_Store+bx]
  185.         add     ax,10
  186.         add     word ptr ds:[si],ax
  187.         add     bp,4
  188.         call    Waiter
  189.         loop    UnReloc_Loop
  190.  
  191. Done_UnReloc:
  192.         pop     bp di si ds es dx cx bx ax
  193.         ret                             
  194. ;------------------------------------------------------------------------
  195. Get_Offset:
  196.         pop     bp
  197.         jmp     short confuzzled
  198.         db      0ea
  199. confuzzled:
  200.         push    bp
  201.         sub     bp,offset Displaced
  202.         ret
  203.  
  204. Done_Waiter:
  205.         ret
  206. Waiter:
  207.         jmp     W1
  208.         db      0ea
  209. W3:
  210.         call    DoKB
  211.         jmp     W4      ;Confuze people.......
  212. W2:
  213.         call    DoKB
  214.         jmp     W3
  215. w4:
  216.         or      bp,bp
  217.         jz      w2
  218.         pop     bp
  219.         jmp     Done_Waiter
  220. W1:
  221.         push    bp
  222.         xor     bp,bp
  223.         jmp     W2
  224.  
  225.         db      'Protection by Black Wolf'
  226.  
  227. DoKB:        
  228.         in      al,21
  229.         xor     al,2
  230.         out     21,al
  231.         inc      bp
  232.         ret
  233. ;------------------------------------------------------------------------
  234. ES_Store        dw      0
  235. ;------------------------------------------------------------------------
  236. Old_IP  dw      0
  237. Old_CS  dw      0fff0
  238. Old_SS  dw      0fff0
  239. Old_SP  dw      0
  240.  
  241. Key1    dw      0
  242. Key2    dw      0
  243. Key3    dw      0
  244. Key4    dw      0
  245. ;------------------------------------------------------------------------
  246. end_prog:
  247. Header:
  248. end start
  249.